//
//  SEExamineAPI.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/14.
//

import Moya

enum SEExamineAPI {
    /// 医院检查项
    case hospitalExamineItems(hospitalId: String)
    /// 检查订单记录
    /// selectSource 查询来源 - 1：APP检查记录列表  2：后台管理  3:PC智慧眼科 4：APP个人中心检查订单列表
    case examineList(pageNum: Int, pageSize: Int, selectSource: Int)
    /// 取消检查预约
    case cancelExamine(applyFormId: String)
    /// 检查单详情
    case examineDetail(applyFormId: String)
    /// 检查单支付
    case payExamine(applyFormId: String)
    /// 取消单项检查
    case cancelExamineItem(formDetailId: String)
    /// 检查记录报告详情
    case examineRecord(applyFormId: String)
    /// 检查提交评价
    /// oldEvaluation 评价内容原文
    /// isAnonymous 是否匿名0-匿名1-不匿名
    case examineSubmitComment(applyFormId: String, score: Float, oldEvaluation: String = "", isAnonymous: Int = 0)
    /// 申请创建AI报告
    case examineAIReportCreate(applyFormId: String, flag: Int, templateId: String)
}

extension SEExamineAPI: TargetType {
    var baseURL: URL {
        return URL(string: SEApiManager.baseUrl)!
    }

    var path: String {
        switch self {
        case .hospitalExamineItems:
            return "/smarteye/smarteye-check/publicCheck/hospitalCheckItem"
        case .examineList:
            return "/smarteye/smarteye-check/appCheck/applyFormList"
        case .cancelExamine:
            return "/smarteye/smarteye-check/appCheck/cancelApplyForm"
        case .examineDetail:
            return "/smarteye/smarteye-check/appCheck/applyFormDetail"
        case .payExamine:
            return "/smarteye/smarteye-check/appCheck/payApplyForm"
        case .cancelExamineItem:
            return "/smarteye/smarteye-check/publicCheck/cancelFormDetail"
        case .examineRecord:
            return "/smarteye/smarteye-check/appCheck/formDetail"
        case .examineSubmitComment:
            return "/smarteye/smarteye-check/checkFormEvaluate/addApplyFormEvaluate"
        case .examineAIReportCreate:
            return "/smarteye/smarteye-check/ai/buildAiReport"
        }
    }

    var method: Moya.Method {
        switch self {
        case .examineDetail,
             .cancelExamineItem,
             .examineRecord,
             .examineAIReportCreate:
            return .get
        default:
            return .post
        }
    }

    var sampleData: Data {
        return "".data(using: .utf8)!
    }

    var task: Task {
        switch self {
        case .cancelExamine,
             .examineDetail,
             .payExamine,
             .cancelExamineItem,
             .examineRecord,
             .examineAIReportCreate:
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        default:
            return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
        }
    }

    var headers: [String : String]? {
        return SEApiManager.headers
    }

    private var parameters: [String: Any] {
        switch self {
        case let .hospitalExamineItems(hospitalId):
            return ["hospitalId": hospitalId]
        case let .examineList(pageNum, pageSize, selectSource):
            return ["pageNum": pageNum,
                    "pageSize": pageSize,
                    "selectSource": selectSource]
        case let .cancelExamine(applyFormId):
            return ["applyFormId": applyFormId]
        case let .examineDetail(applyFormId):
            return ["applyFormId": applyFormId]
        case let .payExamine(applyFormId):
            return ["applyFormId": applyFormId]
        case let .cancelExamineItem(formDetailId):
            return ["formDetailId": formDetailId]
        case let .examineRecord(applyFormId):
            return ["applyFormId": applyFormId]
        case let .examineSubmitComment(applyFormId, score, oldEvaluation, isAnonymous):
            return ["applyFormId": applyFormId,
                    "score": score,
                    "oldEvaluation": oldEvaluation,
                    "isAnonymous": isAnonymous]
        case let .examineAIReportCreate(applyFormId, flag, templateId):
            return ["applyFormId": applyFormId,
                    "flag": flag,
                    "templateId": templateId]
        }
    }
}
